#include "gtest/gtest.h"
#include "cli_wrapper.h"
TEST(CLIPath, RevisePath ) {
CLIPath cliPath;
EXPECT_TRUE( cliPath.Initialize() );
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("/a/");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("/a/b");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/");
cliPath.RevisePath("/a/b/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/");
cliPath.RevisePath("/a/b/c");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/");
cliPath.RevisePath("/a/b/c/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/");
cliPath.RevisePath("/a/b/c/d");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/d/");
cliPath.RevisePath("/a/b/c/d/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/d/");

cliPath.RevisePath("/.");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/./");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/./.");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/././");
EXPECT_EQ( cliPath.BuildPath(), "/");

cliPath.RevisePath("/..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/../");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/../..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/../../");
EXPECT_EQ( cliPath.BuildPath(), "/");

cliPath.RevisePath("/../.");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/./..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/././..//.");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/.//////./../////");
EXPECT_EQ( cliPath.BuildPath(), "/");


cliPath.RevisePath("/a/..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/../");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/../..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/../../");
EXPECT_EQ( cliPath.BuildPath(), "/");

cliPath.RevisePath("/a/b/..");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("/a/b/../");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("/a/b/../..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/b/../../");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/b/../../..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/b/../../../");
EXPECT_EQ( cliPath.BuildPath(), "/");

cliPath.RevisePath("/a/b/../c");
EXPECT_EQ( cliPath.BuildPath(), "/a/c/");
cliPath.RevisePath("/a/b/../c/");
EXPECT_EQ( cliPath.BuildPath(), "/a/c/");
cliPath.RevisePath("/a/b/../../c");
EXPECT_EQ( cliPath.BuildPath(), "/c/");
cliPath.RevisePath("/a/b/../../c/");
EXPECT_EQ( cliPath.BuildPath(), "/c/");
cliPath.RevisePath("/a/b/../../../c");
EXPECT_EQ( cliPath.BuildPath(), "/c/");
cliPath.RevisePath("/a/b/../../../c/");
EXPECT_EQ( cliPath.BuildPath(), "/c/");

cliPath.RevisePath("/a/b/../c/..");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("/a/b/../c/../");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("/a/b/../../c/..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/a/b/../../c/../..");
EXPECT_EQ( cliPath.BuildPath(), "/");
cliPath.RevisePath("/../a/b/../../../c");
EXPECT_EQ( cliPath.BuildPath(), "/c/");
cliPath.RevisePath("/../../a/b/../../../c/");
EXPECT_EQ( cliPath.BuildPath(), "/c/");

cliPath.RevisePath("/a/");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("b/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/");
cliPath.RevisePath("c/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/");
cliPath.RevisePath("..");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/");
cliPath.RevisePath("c/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/");
cliPath.RevisePath("../../");
EXPECT_EQ( cliPath.BuildPath(), "/a/");
cliPath.RevisePath("b/c");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/");
cliPath.RevisePath("../d/");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/d/");
cliPath.RevisePath("../c/d");
EXPECT_EQ( cliPath.BuildPath(), "/a/b/c/d/");
cliPath.RevisePath("../../a/b/../../../c/");
EXPECT_EQ( cliPath.BuildPath(), "/a/c/");
}
TEST(CLIWrapper, GetLine ) {
CLIWrapper cliWrapper;
cliWrapper.Initialize("[","]","$","/", "/input \"abc\"" );
EXPECT_TRUE( strcmp(cliWrapper.GetLine(), "abc") == 0);
}
